import wx from 'weixin-js-sdk'

export default {
  // 加载微信
  inWxJsApi(
    is_debug,
    appid,
    timestamp,
    nonce,
    signature,
    imgUrl,
    lineLink,
    descContent,
    shareTitle) {

    wx.config({
      debug: is_debug,
      appId: appid,
      timestamp: timestamp,
      nonceStr: nonce,
      signature: signature,
      jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'translateVoice',
        'startRecord',
        'stopRecord',
        'onRecordEnd',
        'playVoice',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openCard'
      ]
    });

    wx.ready(function () {
      var shareData = {
        title: shareTitle,
        desc: descContent,
        link: lineLink,
        imgUrl: imgUrl,
        trigger: function () {},
        success: function () {
          alert('已分享:' + shareTitle);
        },
        cancel: function () {
          alert('已取消');
        },
        fail: function () {
          //alert(JSON.stringify(res));
        }
      };

      var shareData_2 = {
        title: descContent,
        desc: shareTitle,
        link: lineLink,
        imgUrl: imgUrl,
        trigger: function () {},
        success: function () {
          alert('已分享:' + shareTitle);
        },
        cancel: function () {
          alert('已取消');
        },
        fail: function () {
          //alert(JSON.stringify(res));
        }
      };

      wx.onMenuShareAppMessage(shareData);
      wx.onMenuShareTimeline(shareData_2); //朋友圈，标题改一下
      wx.onMenuShareQQ(shareData);

      wx.onMenuShareWeibo(shareData);
    });

    wx.error(function () {});

  }
}